<template>
  <el-dialog
  title="查看全部"
  :visible="isShowModel"
  class="priceTemplateModel"
  :before-close="handleClose"
  @close="$emit('update:isShowDetail', false)"
  :close-on-click-modal="false"
  append-to-body>
    <el-form :inline="true" :model="priceTemplateInfo" ref="priceTemplateInfo" @submit.native.prevent>
      <el-form-item label="采购商名称:" prop="yName">
        <el-input v-model="priceTemplateInfo.yName"
                  @keyup.enter.native="onSearch" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSearch()">搜索</el-button>
      </el-form-item>
    </el-form>
    <jxf-table :table="merchantList"></jxf-table>
    <jxf-pagination :pageTotal="pagePriceTotal" :currentPage.sync='currentPricePage' :pageSize.sync="pagePriceSize"
                    @currentPageChange="currentPricePageChange" @pageSizeChange="pagePriceSizeChange"></jxf-pagination>
  </el-dialog>
</template>

<script>
  import FormatDate from '@/assets/js/formatDate'
    export default {
        name: "PriceTemplateModel",
        props: {
          isShowDetail: {
            type: Boolean,
            default: false
          },
          url: {
            type: String,
            default: apis.productAudit.getPriceTemplateist
          }
        },
        data() {
          return {
            isShowModel: this.isShowDetail,
            priceTemplateInfo: {
              id: null,
              yName: ""
            },
            merchantList: {
              border: true,
              loading: true,
              tr: [
                {
                  id: '1',
                  label: '采购商名称',
                  prop: 'yname',
                },
                {
                  id: '2',
                  label: '绑定时间',
                  prop: 'signDate'
                }],
              data: []
            },
            FormatDate: FormatDate,
            currentPricePage: 1,
            pagePriceSize: 10,
            pagePriceTotal: 0,
          }
        },
        methods: {
          init(obj) {
            this.priceTemplateInfo.id = obj.id
            this.getData()
          },
          getData() {
            let data = {
              ...this.priceTemplateInfo
            }
            console.log(this.url)
            ajax.post(this.url, data)
              .then(res => {
                if (res.success === true) {
                  if (res.data !== null) {

                    this.pagePriceTotal = res.data.total
                    if (res.data.dataList !== []) {
                      this.merchantList.data = this.setMerchantList(res.data.dataList)
                    } else {
                      this.merchantList.data = []
                    }
                  }
                } else {
                  this.$message.error(res.message)
                }
                this.merchantList.loading = false
              })
          },
          onSearch() {
            this.currentPricePage = 1;
            this.getData()
          },
          // 切换页面
          currentPricePageChange(pageNo) {
            this.currentPricePage = pageNo
            this.getData()
          },
          // 切换页面条数
          pagePriceSizeChange(pageNo) {
            this.pagePriceSize = pageNo
            this.getData()
          },
          setMerchantList(item) {
            if(item === null){
              return []
            } else {
              return item.map(item => {
                return {
                  id: item.id,
                  jname: item.jname,
                  yname: item.yname,
                  signDate: item.signDate ? this.FormatDate.dateFormat(item.signDate) : ''
                }
              })
            }
          },
          resetForm(formName) {
            this.$refs[formName].resetFields()
          },
          handleClose(done) {
            this.resetForm('priceTemplateInfo')
            this.priceTemplateInfo.id = null
            done()
          }
        },
        watch: {
          isShowDetail(val) {
            this.isShowModel = val
          }
        }
    }
</script>

<style lang="scss">
.priceTemplateModel {
  .el-dialog {
    width: 600px;
  }
}
</style>
